home *** CD-ROM | disk | FTP | other *** search
- Path: netnews.NCTU.edu.tw!usenet
- From: ben@water.ee.nsysu.edu.tw (Benjamin Han)
- Newsgroups: comp.lang.c++
- Subject: CodeGuard: alarm producer or what?
- Date: Fri, 05 Apr 1996 03:44:13 GMT
- Organization: AI lab, dept. of E.E., NSYSU.
- Message-ID: <31648ded.5066048@netnews.nctu.edu.tw>
- Reply-To: ben@water.ee.nsysu.edu.tw
- NNTP-Posting-Host: ben.ee.nsysu.edu.tw
- X-Newsreader: Forte Agent .99d/32.182
-
- Yesterday I tried to rebuild my project with CodeGuard 1.0 for Borland C++ 4.53
- -- just to make sure that no nasty bugs in it any more. It's basically a console
- program accepting an argument so that you can specify the target file you want
- it to deal with. After building, I ran once with a legal file name, and all went
- fine (no alarms, thanks God). Then I deliberately missed the first argument, so
- that the exception throw-and-catch code somewhere in my project could be
- triggered. Guess what? A more-than-500-line errors report was thrown on me. I
- checked the report, and found some destructors were not executed at all before
- the program was terminated. However, I was still not quite sure (Borland is a
- big name, isn't it?) , so I wrote a simple testing code (shown below) and tested
- it,
-
- =============================================================
- class Foo
- {
- char *buffer;
-
- public:
-
- Foo (): buffer(new char[100]) {}
- ~Foo () { delete[] buffer; }
- };
-
-
- void main (void)
- {
- Foo foo;
-
- throw;
- }
- =============================================================
-
- the result: an error report with more than 70 lines. All were complaints about
- 'memory leak' of some blockes allocated by function 'malloc'! When I commented
- out the throw statement, everything was back to normal. Now I'm confused --
- could anybody out there explain this to me? Thanks in advance.
-
-
- Benjamin Han
- AI lab, Dept. of E.E.,
- National Sun Yat-sen Univ.,
- Taiwan, ROC.
-